<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>考试详情 - 英语单词测试系统</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/Chart.js/4.3.0/chart.umd.min.js"></script>
    <script src="{{ url_for('static', filename='js/wordcloud2.min.js') }}"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
    <div class="container-fluid">
        <a class="navbar-brand" href="/exams">英语单词测试系统</a>
        <div class="d-flex">
            <a href="/logout" class="btn btn-outline-light">退出登录</a>
        </div>
    </div>
</nav>
<div class="container mt-5">
    <h4>考试详情</h4>
    <div class="card mb-4">
        <div class="card-body">
            <h5 class="card-title">{{ exam.name }}</h5>
            <p class="card-text">开始时间：{{ exam.start_time.strftime('%Y-%m-%d %H:%M') }}<br>
                结束时间：{{ exam.end_time.strftime('%Y-%m-%d %H:%M') }}<br>
                题目数量：{{ exam.questions|length }}
            </p>
        </div>
    </div>
    <div class="row mb-4">
        <div class="col-md-6">
            <div class="card">
                <div class="card-header bg-primary text-white text-center">成绩分布</div>
                <div class="card-body">
                    <canvas id="scoreChart" height="200"></canvas>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="card">
                <div class="card-header bg-danger text-white text-center">全班错词词云</div>
                <div class="card-body">
                    <div id="wordcloud" style="width:100%;height:200px;"></div>
                </div>
            </div>
        </div>
    </div>
    <h5>题目列表</h5>
    <ul class="list-group mb-4">
        {% for q in exam.questions %}
        <li class="list-group-item">{{ q.word }} - {{ q.meaning }} ({{ q.level }})</li>
        {% endfor %}
    </ul>
    <a href="/exams" class="btn btn-secondary">返回考试列表</a>
</div>
<script>
    // 成绩分布柱状图
    var ctx = document.getElementById('scoreChart').getContext('2d');
    var scores = {{ scores|tojson }};
    var total = {{ exam.questions|length }};
    var bins = Array(total+1).fill(0);
    scores.forEach(function(s){bins[s]++;});
    new Chart(ctx, {
        type: 'bar',
        data: {
            labels: Array.from({length: total+1}, (_,i)=>i),
            datasets: [{label:'人数',data:bins,backgroundColor:'#0d6efd'}]
        },
        options: {scales:{x:{title:{display:true,text:'分数'}},y:{title:{display:true,text:'人数'},beginAtZero:true,ticks:{stepSize:1,precision:0}}}}
    });
    // 全班错词词云
    var wordcloud_data = {{ wordcloud_data|tojson }};
    var words = wordcloud_data.map(function(w){return [w.word, w.count, w.meaning];});
    WordCloud(document.getElementById('wordcloud'), {
        list: words.map(function(item){return [item[0], item[1]];}),
        gridSize: 10,
        weightFactor: 12,
        fontFamily: '微软雅黑',
        color: 'random-dark',
        backgroundColor: '#fff',
        click: function(item, dimension, event){
            var word = item[0];
            var meaning = words.find(function(w){return w[0]===word;})[2];
            var count = item[1];
            alert('单词：'+word+'\n释义：'+meaning+'\n错题次数：'+count);
        }
    });
</script>
</body>
</html> 